<?php
/**
 * 
 * model() 帮助我们创建模型队形 
 * tableName() 帮助我们返回当前数据表的名字 是静态方法
 * @author Administrator
 *
 */
class bd_board extends CActiveRecord {
	// classname就是当前class 名字 chapters
	// 反悔当前模型对象的静态方法 固定的
	public static function model($className = __CLASS__) {
		return parent::model ( $className );
	}
	
	/**
	 * 返回当前数据表的名字
	 */
	public function tableName() {
		// 如果有前缀可以加两个括号 这样会自动关联
		// return '{{chapters}}';
		return 'bd_board';
	}
	
	/*  public function getMangas() {
		return $this->hasMany(mangas::className(), ['id' => 'mid'])
		->viaTable('mangascategories', ['cid' => 'id']);
	}  */
	
	function getBoardListByCid($language, $cid, $type, $page){
		//$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameEn` name2, `descriptionEn` description2";
		$pageSize = 20;
		if ($language == 0) { // origin
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameEn` name2, `descriptionEn` description2";
		} else if ($language == 1) { // Portugues
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `namePor` name2, `descriptionPor` description2";
		} else if ($language == 2) { // ????
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameArabic` name2, `descriptionArabic` description2";
		} else if ($language == 3) { // Italiano
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameItalian` name2, `descriptionItalian` description2";
		} else if ($language == 4) { // English
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameEn` name2, `descriptionEn` description2";
		} else if ($language == 5) { // Francais
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameFrench` name2, `descriptionFrench` description2";
		} else if ($language == 6) { // Deutsch
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameGermany` name2, `descriptionGermany` description2";
		} else if ($language == 7) { // ????
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameChineseSim` name2, `descriptionChineseSim` description2";
		} else if ($language == 8) { // ????
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameChineseSim` name2, `descriptionChineseSim` description2";
		} else if ($language == 9) { // ??
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameCorean` name2, `descriptionCorean` description2";
		} else if ($language == 10) { // ????
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameSpanish` name2, `descriptionSpanish` description2";
		} else if ($language == 11) { // ??
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description,`descriptionEn` descriptionIOS, `nameJpn` name2, `descriptionJpn` description2";
		} else {
			$sqlExt = "SELECT `nameEn` name,`descriptionEn` description";
		}
		
		if ($type == 0) {
			$sql = $sqlExt . ",width, height, picture, id, uid, lng, lat, nation, name, description, nationid, focusNum, tag, street, link, lng, lat, picNum, created_time, pics, time, author  FROM bd_board WHERE cid=$cid AND width != 0 ORDER BY id DESC limit " . ($page - 1) * $pageSize . ", 20";
		} else if ($type == 1) {
			$sql = $sqlExt . ",width, height, picture, id, uid, lng, lat, nation, name, description, nationid, focusNum, tag, street, link, lng, lat, picNum, created_time, pics, time, author  FROM bd_board WHERE width != 0 ORDER BY id DESC  limit " . ($page - 1) * $pageSize . ", 20";
		}
		$boardModel = bd_board::model();
		$boardList = $boardModel->findBySql($sql);
		
		return $boardList;
	}
}